package top.mhtools.pigeon.wechat.service.support;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import top.mhtools.pigeon.common.persistence.WeChatRequest;
import top.mhtools.pigeon.common.util.HttpClientUtil;
import top.mhtools.pigeon.wechat.dto.WeChatMessageReqDTO;

/**
 * 企业微信发送消息执行器
 *
 * @author machen
 * @date 2020/4/24 19:22
 */
@Slf4j
public abstract class AbstractWeChatMessageExecuteStrategy {

    @Value("${wechat.url}")
    protected String wechatUrl;

    @Autowired
    private HttpClientUtil httpClientUtil;

    /**
     * 执行方法
     *
     * @param weChatRequest
     */
    public abstract void execute(WeChatRequest weChatRequest);

    /**
     * 定义标识
     *
     * @return
     */
    public abstract String supports();

    public void sendMessage(WeChatMessageReqDTO weChatMessageReqDTO) {
        String resultStr = httpClientUtil.restApiPost(wechatUrl + weChatMessageReqDTO.getToken(), weChatMessageReqDTO);
        log.info("  >>> 调用企业微信返回数据 :: {}", resultStr);
    }

}
